package com.kh.pajx.sop.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kh.pajx.sop.base.BaseServiceImpl;
import com.kh.pajx.sop.dao.IHsEquOnlineDao;
import com.kh.pajx.sop.domain.HsEquOnline;
import com.kh.pajx.sop.domain.PageBean;
import com.kh.pajx.sop.service.IHsEquOnlineService;
import com.kh.pajx.sop.util.page.QueryHelper;
import com.kh.pajx.sop.util.page.QueryHelperForManyTable;

@Service
@Transactional
public class HsEquOnlineServiceImpl extends BaseServiceImpl<HsEquOnline>
		implements IHsEquOnlineService {

	@Resource
	private IHsEquOnlineDao hsEquOnlineDao;

	@Override
	public void save(HsEquOnline demo) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(Long id) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(String uuid) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(HsEquOnline demo) {
		// TODO Auto-generated method stub

	}

	@Override
	public HsEquOnline getById(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public HsEquOnline getById(String uuid) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<HsEquOnline> findAll() {
		return null;
	}

	@Override
	public PageBean getPageBean(int pageNum, int pageSize,
			QueryHelper queryHelper) {
		return null;
	}

	@Override
	public PageBean getPageBean(int pageNum, int pageSize,
			QueryHelperForManyTable queryHelper) {
		return null;
	}

	@Override
	public PageBean getPageBean(int pageNum, int pageSize, String listHQL,
			String countHQL) {
		return null;
	}

	@Override
	public List<HsEquOnline> findListByHql(String queryString, Object... values) {
		return null;
	}

	@Override
	public void addEquStatus() {
		hsEquOnlineDao.addEquOnline();
	}

	@Override
	public List<HsEquOnline> findEquOnline(String sclId,String equType,String equNo, String whatDay) {
		long date = 0L;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		Date dateTime = new Date();
		Calendar cal = Calendar.getInstance();
		cal.setTime(dateTime); // 计算时间
		List<HsEquOnline> equOnlines = new ArrayList<HsEquOnline>();
		long no = 0L;
		if (StringUtils.isNotEmpty(whatDay) && !whatDay.equals("")) {
			cal.add(Calendar.DAY_OF_MONTH, -(Integer.parseInt(whatDay.trim())-1));
			String dateStr = sdf.format(cal.getTime());
			date=Long.valueOf(dateStr.trim()+"000000");
			no = Long.valueOf(equNo);
		} else {
			String dateStr = sdf.format(cal.getTime());
			date=Long.valueOf(dateStr.trim()+"000000");
		}
		List<List> lists = hsEquOnlineDao.findEquOnline(sclId,equType,no,
				date);
		//把查询出的字段封装成HsEquOnline对象，并放到集合里
		for (List list : lists) {
			HsEquOnline heo = new HsEquOnline();
			heo.setEquNo(Long.valueOf((String) list.get(0)));
			heo.setOnLineStatusFlag((String) list.get(1));
			heo.setMonitorTime((String) list.get(2));
			equOnlines.add(heo);
		}
		return equOnlines;
	}

}
